import 'package:get/get.dart';
import 'package:flustars/flustars.dart';
import 'package:tplib/base/base_view_model.dart';
import 'package:tplib/route/navigator.dart';
import 'package:tplib/route/route_config.dart';
import 'package:tplib_example/service/module_comm_service.dart';

class LoginViewModel extends BaseViewModel<ModuleCommService>{

  RxInt value=0.obs;
  RxString account=''.obs;
  RxString password=''.obs;
  //是否同意用户协议
  RxBool isAgreementSelected=true.obs;
  //是否登录按钮高亮
  RxBool isLoginFocus=false.obs;

  ModuleCommService? moduleCommService;

  @override
  ModuleCommService createService()=>(moduleCommService=ModuleCommService());


  inputChanged(value, int index) {
    switch(index){
      case 0:
        account.value=value?.trim()??'';
        //监听输入框，便于控制登录按钮颜色
        _setLoginBottonColor();
        break;
      case 1:
        password.value=value?.trim()??'';
        _setLoginBottonColor();
        break;
    }
  }

  //监听输入框，便于控制登录按钮颜色
  _setLoginBottonColor(){
    isLoginFocus.value=false;
    LogUtil.e('_setLoginBottonColor-->_account-->$account,_password-->$password');
    if((account.value).trim().isNotEmpty&&((password.value).trim().isNotEmpty))isLoginFocus.value=true;
  }

  login()async {
    // NavigatorUtils.pushByName(RouteConfig.enterprisePage,arguments: {'account':account.value,'password':password.value},
    //     resultFunc: (result){
    //       print('下一个模块页面返回的值-->result=$result');
    //       if((result!=null)&&(result is Map)){
    //         value.value=result['value']??0;
    //       }
    //     });
  }

  selectAgreement() {
    isAgreementSelected.value=!(isAgreementSelected.value);
  }

  toUserAgreement() {}

}